<?php

/**
 * This is the model class for table "{{pttransaction}}".
 *
 * The followings are the available columns in table '{{pttransaction}}':
 * @property string $idpttransaction
 * @property string $idptmaster
 * @property string $idccfyear
 * @property string $receiptno
 * @property string $receiptdate
 * @property string $oldbalance
 * @property string $bhadamulya
 * @property string $shikshaupkar
 * @property string $ptax
 * @property string $surcharge
 * @property string $totaldemand
 * @property string $collection
 *
 * The followings are the available model relations:
 * @property Ccfyear $idccfyear0
 * @property Ptmaster $idptmaster0
 */
class Pttransaction extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Pttransaction the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{pttransaction}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('idptmaster', 'required'),
			array('idptmaster, idccfyear', 'length', 'max'=>10),
			array('receiptno', 'length', 'max'=>100),
			array('oldbalance, bhadamulya, shikshaupkar, ptax, surcharge, totaldemand, collection', 'length', 'max'=>15),
			array('receiptdate', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idpttransaction, idptmaster, idccfyear, receiptno, receiptdate, oldbalance, bhadamulya, shikshaupkar, ptax, surcharge, totaldemand, collection', 'safe', 'on'=>'search'),
                        array('idptmaster, idccfyear', 'validatefkeys'),
		);
	}        
        
        public function validatefkeys($attribute,$params){
               $aux = $attribute . '0';
               if(!$this->$aux)
                    $this->addError($attribute, Yii::t('application', 'Incorrect {attribute}.', array('{attribute}'=>Yii::t('application', $attribute))));
        }      
        
        
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idccfyear0' => array(self::BELONGS_TO, 'Ccfyear', 'idccfyear'),
			'idptmaster0' => array(self::BELONGS_TO, 'Ptmaster', 'idptmaster'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idpttransaction' => Yii::t('application', 'Idpttransaction'),
			'idptmaster' => Yii::t('application', 'Idptmaster'),
			'idccfyear' => Yii::t('application', 'Idccfyear'),
			'receiptno' => Yii::t('application', 'Receiptno'),
			'receiptdate' => Yii::t('application', 'Receiptdate'),
			'oldbalance' => Yii::t('application', 'Oldbalance'),
			'bhadamulya' => Yii::t('application', 'Bhadamulya'),
			'shikshaupkar' => Yii::t('application', 'Shikshaupkar'),
			'ptax' => Yii::t('application', 'Ptax'),
			'surcharge' => Yii::t('application', 'Surcharge'),
			'totaldemand' => Yii::t('application', 'Totaldemand'),
			'collection' => Yii::t('application', 'Collection'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idpttransaction',$this->idpttransaction,true);
		$criteria->compare('idptmaster',$this->idptmaster,true);
		$criteria->compare('idccfyear',$this->idccfyear,true);
		$criteria->compare('receiptno',$this->receiptno,true);
		$criteria->compare('receiptdate',$this->receiptdate,true);
		$criteria->compare('oldbalance',$this->oldbalance,true);
		$criteria->compare('bhadamulya',$this->bhadamulya,true);
		$criteria->compare('shikshaupkar',$this->shikshaupkar,true);
		$criteria->compare('ptax',$this->ptax,true);
		$criteria->compare('surcharge',$this->surcharge,true);
		$criteria->compare('totaldemand',$this->totaldemand,true);
		$criteria->compare('collection',$this->collection,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}